package com.cadre.web.controller.officer;

import com.cadre.common.utils.R;
import com.cadre.system.service.DIC_ZBService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Api(tags = {"字典表接口"})
@RequestMapping({"/profess/DIC"})
@RestController
/* loaded from: DICController.class */
public class DICController {
    @Resource
    private DIC_ZBService dIC_ZBService;

    @RequestMapping(value = {"/getDICTable"}, method = {RequestMethod.GET})
    @ApiOperation("读取字典")
    public R getDICTable(@RequestParam String tableName) {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        return R.ok().put("data", (Object) this.dIC_ZBService.getAll(map));
    }

    @RequestMapping(value = {"/getDICTableByI"}, method = {RequestMethod.GET})
    @ApiOperation("读取字典ByI")
    public R getDICTableByI(@RequestParam String tableName) {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        return R.ok().put("data", (Object) this.dIC_ZBService.selectAllByImportance(map));
    }

    @RequestMapping(value = {"/getDICTableLike"}, method = {RequestMethod.GET})
    @ApiOperation("读取字典模糊")
    public R getDICTableLike(@RequestParam String tableName, @RequestParam String name) {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        map.put("name", name);
        return R.ok().put("data", (Object) this.dIC_ZBService.selectAllLikeName(map));
    }

    @RequestMapping(value = {"/CreateTable"}, method = {RequestMethod.GET})
    @ApiOperation("创建字典表")
    public R CreateTable(String tableName, String tableType) {
        String mString = tableName.substring(0, 3).toUpperCase();
        System.out.println(mString);
        if (!"DIC".equals(mString)) {
            return R.error();
        }
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        this.dIC_ZBService.createTable(map);
        map.put("tableType", tableType);
        this.dIC_ZBService.comment(map);
        return R.ok();
    }

    @RequestMapping(value = {"/DropTable"}, method = {RequestMethod.GET})
    @ApiOperation("删除字典表")
    public R DropTable(String tableName) {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        this.dIC_ZBService.dropTable(map);
        return R.ok();
    }

    @RequestMapping(value = {"/DropTableItem"}, method = {RequestMethod.POST})
    @ApiOperation("删除字典表节点")
    public R DropTable(@RequestBody Map<String, Object> map) {
        if (this.dIC_ZBService.deleteByPrimaryKey(map) == 1) {
            return R.ok();
        }
        return R.error();
    }

    @RequestMapping(value = {"/selectViewDic"}, method = {RequestMethod.GET})
    @ApiOperation("查询字典表视图")
    public R selectViewDic() {
        return R.ok().put("data", (Object) this.dIC_ZBService.selectViewDic());
    }

    @RequestMapping(value = {"/comment"}, method = {RequestMethod.GET})
    @ApiOperation("更新字典表备注")
    public R comment(String tableName, String tableType) {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        map.put("tableType", tableType);
        this.dIC_ZBService.comment(map);
        return R.ok();
    }

    @RequestMapping(value = {"/addDic"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public R addDic(@RequestBody Map<String, Object> map) {
        if (this.dIC_ZBService.insertSelective(map) == 1) {
            return R.ok();
        }
        return R.error();
    }

    @RequestMapping(value = {"/updateDic"}, method = {RequestMethod.POST})
    @ApiOperation("更新")
    public R updateDic(@RequestBody Map<String, Object> map) {
        if (this.dIC_ZBService.updateByPrimaryKeySelective(map) == 1) {
            return R.ok();
        }
        return R.error();
    }

    @RequestMapping(value = {"/updateDicOrder"}, method = {RequestMethod.POST})
    @ApiOperation("更新排序")
    public R updateDicOrder(@RequestBody String[] code, @RequestBody String tableName) {
        if (code.length == 0) {
            return R.error();
        }
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        for (int i = 0; i < code.length; i++) {
            map.put("code", code[i]);
            map.put("orderid", Integer.valueOf(i));
            this.dIC_ZBService.updateByPrimaryKeySelective(map);
        }
        return R.ok();
    }

    @RequestMapping(value = {"/getDIC_ZB125"}, method = {RequestMethod.GET})
    public R getDIC_ZB125() {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", "DIC_ZB125");
        return R.ok().put("data", (Object) this.dIC_ZBService.getAll(map));
    }

    @RequestMapping(value = {"/getDIC_ZB1004"}, method = {RequestMethod.GET})
    public R getDIC_ZB1004() {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", "DIC_ZB1004");
        return R.ok().put("data", (Object) this.dIC_ZBService.getAll(map));
    }

    @RequestMapping(value = {"/getDIC_ZB09"}, method = {RequestMethod.GET})
    public R getDIC_ZB09() {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", "DIC_ZB09");
        return R.ok().put("data", (Object) this.dIC_ZBService.getAll(map));
    }
}
